import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Admin from '../views/Admin.vue'
import Personage from '../views/Personage.vue'
import Inventory from '../views/Inventory.vue'
import Login from '../components/login/login.vue'
import Brand from '../components/brand/index.vue'
import Unit from '../components/unit/index.vue'
import Class from '../components/class/index.vue'
import SPU from '../components/spu/index.vue'
import SKU from '../components/sku/index.vue'
import Warehouse from '../components/warehouse/index.vue'
import Location from '../components/storage_location/index.vue'
import User from '../components/user/index.vue'
import Subject from '../components/subject/index.vue'
import Duty from '../components/duty/index.vue'
import PutInStorage from '../components/put_in_storage/index.vue'
import PutOutStorage from '../components/put_out_storage/index.vue'
import OutOrInWarehose from '../components/out_put_and_in_put_of_warehouse/index.vue'
import GoodsQuantity from '../components/goods_quantity/index.vue'
import Odd from '../components/odd/index.vue'
import OddDetail from '../components/odd_detail/index.vue'
import Test from '../components/test/index.vue'
import MoveSku from '../components/move_sku/index.vue'
import MoveSkuWarehouse from '../components/move_sku_worehouse/index.vue'
import DelWaitOdd from '../components/del_wait_odd/index.vue'
import GoodsAdmin from '../components/goods_admin/index.vue'
import Cookies from 'js-cookie'
import {
	verify_token_url
} from "../utils/setting.js"

Vue.use(VueRouter)

const routes = [{
		path: '/',
		name: 'Home',
		component: Home
	},
	{
		path: '/test',
		name: 'Test',
		component: Test
	},
	{
		path: '/goods_admin',
		name: 'GoodsAdmin',
		component: GoodsAdmin
	},
	{
		path: '/DelWaitOdd',
		name: 'DelWaitOdd',
		component: DelWaitOdd
	},
	{
		path: '/MoveSkuWarehouse',
		name: 'MoveSkuWarehouse',
		component: MoveSkuWarehouse
	},
	{
		path: '/MoveSku',
		name: 'MoveSku',
		component: MoveSku
	},
	
	{
		path: '/odd',
		name: 'Odd',
		component: Odd
	},
	
	{
		path: '/odd_detail',
		name: 'OddDetail',
		component: OddDetail
	},
	// {
	//   path: '/about',
	//   name: 'About',
	//   // route level code-splitting
	//   // this generates a separate chunk (about.[hash].js) for this route
	//   // which is lazy-loaded when the route is visited.
	//   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
	// },
	{
		path: '/login',
		name: 'Login',
		component: Login
	},
	{
		path: '/admin',
		name: 'Admin',
		component: Admin
	},
	{
		path: '/inventory',
		name: 'Inventory',
		component: Inventory
	},
	{
		path: '/brand',
		name: 'Brand',
		component: Brand
	},
	{
		path: '/unit',
		name: 'Unit',
		component: Unit
	},
	{
		path: '/class',
		name: 'Class',
		component: Class
	},
	{
		path: '/spu',
		name: 'SPU',
		component: SPU
	},
	{
		path: '/sku',
		name: 'SKU',
		component: SKU
	},
	{
		path: '/warehouse',
		name: 'Warehouse',
		component: Warehouse
	},
	{
		path: '/storage_location',
		name: 'Location',
		component: Location
	},
	{
		path: '/user',
		name: 'User',
		component: User
	},
	{
		path: '/subject',
		name: 'Subject',
		component: Subject
	},
	{
		path: '/duty',
		name: 'Duty',
		component: Duty
	},
	{
		path: '/personage',
		name: 'Personage',
		component: Personage
	},
	{
		path: '/put_in_storage',
		name: 'PutInStorage',
		component: PutInStorage
	},
	{
		path: '/put_out_storage',
		name: 'PutOutStorage',
		component: PutOutStorage
	},
	{
		path: '/OutOrInWarehose',
		name: 'OutOrInWarehose',
		component: OutOrInWarehose
	},
	
	{
		path: '/GoodsQuantity',
		name: 'GoodsQuantity',
		component: GoodsQuantity
	},

	

]

const router = new VueRouter({
	mode: 'hash',
	base: process.env.BASE_URL,
	routes
})
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
	return VueRouterPush.call(this, to).catch(err => err)
}


router.beforeEach((to, from, next) => {
	// console.log(to)
	// console.log(from)

	let ignore = ['/login'] //不用登录状态的连接

	for (let i = 0; i < ignore.length; i++) { //判断当前链接是否可以忽略验证

		if (to.path === ignore[i]) {

			next()

		}
	}


	let user_id = Cookies.get('user_id')
	let token = Cookies.get('token')

	if (user_id === undefined) {

		console.log('user_id为undefined')

		router.push({
			'name': 'Login'
		})

	}


	next();

})
export default router
